Completed
Push — master ( e193d1...415e1b )
by Justin
01:32
created

AtomCommon.toJSON   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 3
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 3
loc 3
rs 10
1 View Code Duplication
var utils = require('../utils'),
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
    Base = require('../Base');
3
4
/**
5
 * Common attributes for all Atom entities
6
 * 
7
 * @constructor
8
 * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
9
 */
10
var AtomCommon = function(json){
11
  
12
  // Protect against forgetting the new keyword when calling the constructor
13
  if(!(this instanceof AtomCommon)){
14
    return new AtomCommon(json);
15
  }
16
  
17
  // If the given object is already an instance then just return it. DON'T copy it.
18
  if(AtomCommon.isInstance(json)){
19
    return json;
20
  }
21
  
22
  this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
23
};
24
25
AtomCommon.prototype = Object.create(Base.prototype);
26
27
AtomCommon._gedxClass = AtomCommon.prototype._gedxClass = 'GedcomX.AtomCommon';
28
29
AtomCommon.jsonProps = [
30
  'base',
31
  'lang'
32
];
33
34
/**
35
 * Check whether the given object is an instance of this class.
36
 * 
37
 * @param {Object} obj
38
 * @returns {Boolean}
39
 */
40
AtomCommon.isInstance = function(obj){
41
  return utils.isInstance(obj, this._gedxClass);
42
};
43
44
/**
45
 * Initialize from JSON
46
 * 
47
 * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
48
 * @return {AtomCommon} this
49
 */
50
AtomCommon.prototype.init = function(json){
51
  
52
  Base.prototype.init.call(this, json);
53
  
54
  if(json){
55
    this.setBase(json.base);
56
    this.setLang(json.lang);
57
  }
58
  return this;
59
};
60
61
/**
62
 * Set the base attribute
63
 * 
64
 * @param {String} base
65
 * @return {AtomCommon} this
66
 */
67
AtomCommon.prototype.setBase = function(base){
68
  this.base = base;
69
  return this;
70
};
71
72
/**
73
 * Get the base
74
 * 
75
 * @return {String} base
76
 */
77
AtomCommon.prototype.getBase = function(base){
78
  return this.base;
79
};
80
81
/**
82
 * Set the lang
83
 * 
84
 * @param {String} lang
85
 * @return {AtomCommon} this
86
 */
87
AtomCommon.prototype.setLang = function(lang){
88
  this.lang = lang;
89
  return this;
90
};
91
92
/**
93
 * Get the lang
94
 * 
95
 * @return {String} lang
96
 */
97
AtomCommon.prototype.getLang = function(lang){
98
  return this.lang;
99
};
100
101
/**
102
 * Export the object as JSON
103
 * 
104
 * @return {Object} JSON object
105
 */
106
AtomCommon.prototype.toJSON = function(){
107
  return this._toJSON(Base, AtomCommon.jsonProps);
108
};
109
110
module.exports = AtomCommon;
111